#include <iostream>
#include <fstream>
#include <vector>
#include <chrono>
#include <ctime>
#include <ratio>
#include <conio.h>
#include <queue>
#include <stack>
#include <deque>
#include <iomanip>
#include <string>
#include <algorithm>
#include "Node.h"

#pragma once

using namespace std;

class ordered_list
{
private:
	Node *head;
	Node *tail;
	Node *freehead;
public:

	ordered_list(void)
	{
		head = tail = nullptr;
	}

	ordered_list(int size_free_list)
	{
		head = tail = nullptr;
		for (int i = 0; i < size_free_list; i++)
		{
			Node *temp;
			temp = new Node();
			temp -> next = freehead;
			freehead = temp;
		}
	}

	void Add(string word)
    {
		Node *temp = head;
		if(head == nullptr)
        {
			head = new Node(word, 1);
			head -> next = nullptr;
        }
        else
        {
			do
			{
				if (temp -> word.compare(word) == 0)
				{
					temp ->amount++;
					break;
				}
				if ((temp -> word.compare(word) > 0) && (temp -> next == nullptr))
				{
					Node *n1 = new Node(word, 1);
					n1 -> next = temp -> next;
					temp -> next = n1;
					break;
				}
				else if ((temp -> word.compare(word) > 0) && (temp -> next -> word.compare(word) < 0))
				{
					Node *n1 = new Node(word, 1);
					n1 -> next = temp -> next;
					temp -> next = n1;
					break;
				}
				else if(temp ->next == nullptr) 
				{
					Node *n1 = new Node(word, 1);
					n1 -> next = nullptr;
					temp -> next = n1;
					break;
				}
				
				temp = temp -> next;
			}while(temp -> next != nullptr);
			
        }
    }

	~ordered_list(void)
	{

	}
};

